﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Xml;
using LitJson;
using MediaPortal.GUI.Library;
using System.Threading;
using System.Net;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.IO; 


namespace MediaPortal.Plugins.Trailers.Providers
{
    public class MovieMazeTrailers : TrailerProviderBase
    {
        #region Variables

        #region MovieMaze Trailer Trailer Locations

        public const string urlBase = "http://www.moviemaze.de";
       
        #endregion

        #endregion

        #region TrailerProviderBase overrides

        public override string ProviderId()
        {
            return "4";
        }

        public override string ProviderName()
        {
            return "MovieMaze Trailers";
        }

        public override string ProviderImage()
        {
            return "http://www.moviemaze.de/logo_234x60.gif";
        }

        public override Index GetIndex()
        {
            Index rtIndex = new Index();
            rtIndex.Add(new IndexItem("Last Updated", "/last_updated", true));
            rtIndex.Add(new IndexItem("Last Updated (HD)", "/last_updated_hd", true));
            rtIndex.Add(new IndexItem("Top 10", "/top10", true));
            rtIndex.Add(new IndexItem("Recent", "/recent", true));
            rtIndex.Add(new IndexItem("Archiv", "/archiv", true));
            return rtIndex;
        }

        public override Index GetIndex(string key)
        {
            Log.Info("[MyTrailers][MovieMaze Trailers] Retrieving index: {0}", key);
            switch (key)
            {
                case "/last_updated":
                    {
                        MovieMazeTrailerOverview page = new MovieMazeTrailerOverview();
                        return page.fetchLastUpdates();
                    }
                case "/last_updated_hd":
                    {
                        MovieMazeTrailerOverview page = new MovieMazeTrailerOverview();
                        return page.fetchLastUpdatesHD();
                    }
                case "/top10":
                    {
                        MovieMazeTrailerOverview page = new MovieMazeTrailerOverview();
                        return page.fetchTop10();
                    }
                case "/recent":
                    {
                        MovieMazeTrailerOverview page = new MovieMazeTrailerOverview();
                        return page.fetchRecent();
                    }
                case "/archiv":
                default:
                    {
                        MovieMazeArchivPage page = new MovieMazeArchivPage();
                        return page.fetchTrailerList();
                    }
            }

        }

        public override Trailer GetDetails(string key)
        {
            Log.Info("[MyTrailers][MovieMaze Trailers] Retrieving details: {0}", key);

            MovieMazeTrailerPage page = new MovieMazeTrailerPage();
            return page.fetchTrailer(key);
        }

        // Todo: use interface method
        public string resolveUrl(string url)
        {
            MovieMazeTrailerWebClient client = new MovieMazeTrailerWebClient();
            return client.getRedirectedPage(url);
        }

        #endregion
 
    }

    
}

